package com.example;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText number;
    private EditText number1;
    private EditText del;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.but).setOnClickListener(this);
        number = findViewById(R.id.num1);
        number1 = findViewById(R.id.num2);
        del = findViewById(R.id.fuhao);
    }

    @Override
    public void onClick(View view) {
        //int num1 =Integer.parseInt(number.getText().toString());
        //char n1= (char) Double.parseDouble(number.getText().toString());
        //int num2=Integer.parseInt(number1.getText().toString());
        // char n2=(char)Double.parseDouble(number1.getText().toString());
        double num1 = Double.parseDouble(number.getText().toString());
        double num2 = Double.parseDouble(number1.getText().toString());
        String fuhao = del.getText().toString();
        double total = 0;
        switch (fuhao) {
            case "*":
                total = num1 * num2;
                Toast.makeText(this, "最终的结果为:" + total, Toast.LENGTH_SHORT).show();
                break;
            case "-":
                total = num1 - num2;
                Toast.makeText(this, "最终的结果为:" + total, Toast.LENGTH_SHORT).show();
                break;
            case "+":
                total = num1 + num2;
                Toast.makeText(this, "最终的结果为:" + total, Toast.LENGTH_SHORT).show();
                break;
            case "/":
                total = num1 / num2;
                Toast.makeText(this, "最终的结果为:" + total, Toast.LENGTH_SHORT).show();
                break;
            default:
                Toast.makeText(this, "输入有误请重新输入！！！", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
